import { defHttp } from "/@/utils/http/axios"
import { UploadFileParams } from "/#/axios"
import { AxiosProgressEvent } from "axios"
enum Api {
  virtualToRealBaseUrl = "/infra-service/file/virtualToRealBaseUrl",
}

/**
 * 将虚拟地址转成真实文件地址
 * @param virtualUrl 虚拟url
 * @returns
 */
export function virtualToRealBaseUrl(virtualUrl) {
  return defHttp.get({ url: Api.virtualToRealBaseUrl, params: { virtualUrl } })
}


/**
 * 获取上传令牌
 */
export function getUploadToken(params) {
  return defHttp.post({ url: '/infra-service/file/getUploadToken', params: { 
    name: params.name,
    size: params.size,
    bizType: params.bizType,
    contentType: params.contentType,
  }})
}



export const pageFileConfig = (params) => defHttp.get({ url: "/infra-service/fileConfig/page", params })
export const getFileConfig = (params) => defHttp.get({ url: "/infra-service/fileConfig/get", params })

export const deleteFileConfig = (params, handleSuccess) => {
  return defHttp.delete({ url: "/infra-service/fileConfig/delete", params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}

export const saveOrUpdateFileConfig = (params, isUpdate) => {
  const url = isUpdate ? "/infra-service/fileConfig/update" : "/infra-service/fileConfig/save"
  return defHttp.post({ url: url, params })
}


/**
 * @description: Upload interface
 */
export function uploadApi(uploadUrl, params: UploadFileParams, onUploadProgress: (progressEvent: AxiosProgressEvent) => void, isReturnResponse: boolean = false) {
  return defHttp.uploadFile<any>(
    {
      url: uploadUrl,
      onUploadProgress,
    },
    params,
    { isReturnResponse }
  )
}
